<?php

namespace App\Home\Controllers;

use App\Home\Filters\WorshipBibleChapterFilter;
use App\Home\Models\WorshipBibleChapter;
use App\Home\Requests\WorshipBibleChapterRequest;
use App\Home\Resources\WorshipBibleChapterResource;
use Illuminate\Http\Request;

class WorshipBibleChapterController extends Controller
{
    public function store(
        WorshipBibleChapterRequest $request, 
        WorshipBibleChapter $worshipBibleChapter
    ){
        $inputs = $request->validated();
        $worshipBibleChapter = $worshipBibleChapter->add($inputs);

        return $this->created(WorshipBibleChapterResource::make($worshipBibleChapter));
    }

    public function update(
        WorshipBibleChapterRequest $request, 
        WorshipBibleChapter $worshipBibleChapter
    ){
        $inputs = $request->validated();
        $worshipBibleChapter->update($inputs);

        return $this->created(WorshipBibleChapterResource::make($worshipBibleChapter));
    }

    public function destroy(
        WorshipBibleChapter $worshipBibleChapter
    ){
        $worshipBibleChapter->delete();
        return $this->noContent();
    }

    public function index(
        WorshipBibleChapterRequest $request,
        WorshipBibleChapterFilter $filter
    ){
        $fields = [
            "*",
        ];
        $worshipBibleChapters = WorshipBibleChapter::query()
            ->filter($filter)
            ->select($fields)
            ->paginate();

        return $this->ok(WorshipBibleChapterResource::collection($worshipBibleChapters));
    }

    public function show(
        Int $id
    ){
        $fields = [
            "*",
        ];
        $worshipBibleChapter = WorshipBibleChapter::query()
            ->select($fields)
            ->find($id);
        return $this->ok(WorshipBibleChapterResource::make($worshipBibleChapter));
    }
}
